let rqCnt = 0;
export const getRequest =(params)=>{
  rqCnt++;
  wx.showLoading({
    title: '正在努力处理中...',
    mask:true
  });
  let hearder = params.header || {'content-type':'application/json'};
  let dataType = params.dataType|| 'json';
  return new Promise((resolve,reject)=>{
    wx.request({
      url: params.url,
      method:'GET',
      data:params.data,
      header:hearder,
      dataType:dataType,
      success:(result)=>{
         console.log(result)
         resolve(result);
      },
      fail:(error)=>{
         reject(error);
      },
      complete:()=>{
        rqCnt--;
        if(rqCnt===0){
          wx.hideLoading();
        }
      }
    });
  }); 
}

export const postRequest =(params)=>{
  rqCnt++;
  wx.showLoading({
    title: '正在努力处理中...',
    mask:true
  });
  let hearder = params.header || {'content-type':'application/json'};
  return new Promise((resolve,reject)=>{
    wx.request({
      url: params.url,
      method:'POST',
      data:params.data,
      header:hearder,
      success:(result)=>{
        console.log(result)
         resolve(result);
      },
      fail:(error)=>{
         reject(error);
      },
      complete:()=>{
        rqCnt--;
        if(rqCnt===0){
          wx.hideLoading();
        }
      }
    });
  }); 
}